<?php
/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function quedesparche_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];
  $breadcrumb[] = l(drupal_get_title(), $_GET["q"]);
  if (!empty($breadcrumb)) {
    $output = '<ul>';
    $first = true;
    foreach ($breadcrumb as $key => $value) {
      if ($first) {
        $output .= '<li>' . $value . '</li>';
        $first = false;
      } else {
        $pos = strpos($value, ">");
        $innerText = substr($value, $pos + 1, (strlen($value) - $pos - 5));
        if (strlen($innerText) > 45) {
          $newValue = substr($innerText, 0, 42) . "...";
          $value = str_replace($innerText, $newValue, $value);
        }
        $output .= '<li>&gt;</li><li>' . decode_entities($value) . '</li>';
      }
    }
    $output .= '</ul>';
	
    return $output;
  }
}
/**
 * Override or insert variables into the html template.
 */
function quedesparche_process_html(&$vars) {
  $node = current_node();
  $vars['scripts'] = drupal_get_js();
 
}

/**
 * Override or insert variables into the page template.
 */
 
function quedesparche_preprocess_page(&$vars) {
  $global_config = node_load(98);
  $node = current_node();
  $vars['global_config'] = $global_config;
  $vars['template'] = '';
  $vars['header_wrapper_height'] = 'internal';
  $vars['galeria'] = create_slideshow(); 
  $vars['galeria_temas_varios'] = create_slideshow_temas_varios();
  $vars['path_to_theme']=path_to_theme();

  
  //print_r($_GET);
 /* if (drupal_is_front_page()) {
      $vars['template'] = "home.inc";
	  $vars['shadow_logo'] = '<div id="shadow_logo"></div>';
	  $vars['header_wrapper_height'] = 'home';
      $output = "";
  }*/
 
  
}


function llamarNodoIdioma($nid){
  global $language;
  static $translations = array();  
  $node=NULL;
  $lang = $language->language;
  $base_node = node_load($nid);
  $translations = translation_node_get_translations($base_node->tnid);
  $node = (isset($translations[$lang])?node_load($translations[$lang]->nid):$base_node);
  return $node;
}
//

function create_slideshow() {
  $galeria=llamarNodoIdioma(4);
  $output = "";
  $output .= "<div class='slider-wrapper theme-default'>";
   $output .= "<div id='slider' class='nivoSlider'>";
  for ($c = 0; $c < count($galeria->field_imagen['und']); $c++) {
    $output .= "<div class='slideimage'>";
	
//	$img_url = $node->field_image['und'][0]['uri'];
	//print image_style_url('galeriamain_style'), $img_url);
	
    $field_id = $galeria->field_imagen['und'][$c]['uri'];
    if (count($field_id)) {
      $output .= "<img src='".image_style_url('galeriamain_style', $field_id)."'  alt='".$galeria->field_imagen['und'][$c]['alt']."' title='".$galeria->field_imagen['und'][$c]['title']."' />";
    }
    $output .= "</div>";  
  }
   $output .= "</div>";  
   $output .= "<div id='htmlcaption' class='nivo-html-caption'>
		         <strong>This</strong> is an example of a <em>HTML</em> caption with <a href='#'>a link</a>. 
	           </div>";
$output .= "</div>";  	
return $output;

}

function create_slideshow_temas_varios() {
  $galeria=llamarNodoIdioma(63);
  $patch_img = path_to_theme();
  $output = "";
  $output .= "<ul id='slider-one'>";
	for ($c = 0; $c < count($galeria->field_imagen2['und']); $c++) {
		$output .= "<li>";
		$output .= "<div style='height:auto;'>";
		$field_id = $galeria->field_imagen2['und'][$c]['uri'];
		if (count($field_id)) {
			$output .= "<img src='".image_style_url('galeria_temas_varios', $field_id)."'  alt='".$galeria->field_imagen2['und'][$c]['alt']."' title='".$galeria->field_imagen2['und'][$c]['title']."' />";
		}
		
		$output .= "<h2><b style='font-size:18px'>".$galeria->field_imagen2['und'][$c]['title']."</b>";	
		$output .= "<p style=''>".$galeria->field_imagen2['und'][$c]['alt']."</p></h2>";
		$output .= "</div>";	
		$output .= "</li>";	
	} 
	
	$output .= "</ul>";
	return $output;
}

/** Load the current node **/
function current_node(){
    if(arg(0)=='node'&&is_numeric(arg(1))){
        return node_load(arg(1));       
    }
}



